# -*- coding: utf-8 -*-
"""
Created on 15-12-29 上午11:41
@File: baidu_login.py
@Author: Liangrong Li
@Contact: liliangrong0@126.com
@Description: 通过获取的cookie登陆百度站长平台
参考：http://blog.csdn.net/warrior_zhang/article/details/50198699
"""

import urllib2
login_url = 'http://zhanzhang.baidu.com/dashboard/index'
with open('cookie_zhanzhang.txt','r+') as f:
    cookiestr = f.readlines()
f.closed
headers = {'cookie':cookiestr}
req = urllib2.Request(login_url,headers=headers)
try:
    resp = urllib2.urlopen(req)
    html = resp.read()
    with open('zhanzhang.html','w+') as f:
        f.write(html)
    f.closed
    print u'登陆成功！'
except:
    print u'登录失败！'